package com.s4j.struts.biz.action;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.s4j.struts.biz.service.LiverAnalyService;

@Controller("com.s4j.struts.biz.action.LiverAnalyAction")
@Scope("prototype")
public class LiverAnalyAction {
	
	@Resource
	private LiverAnalyService liverAnalyService;

	public String liverAnaly_ageAnaly() {
		
		HttpServletRequest request = ServletActionContext.getRequest();
		
		List<Object[]> resList = liverAnalyService.liverAnaly_ageAnaly();
		String data = "";
		for(int i=0; i<resList.size(); i++) {
			Object[] objArr = resList.get(i);
			String xt = (String)objArr[1];
			String xv = ((BigInteger)objArr[2]).toString();
			
			if(i == 0) {
				data = "['" + xt + "'," + xv + "]"; 
			} else {
				data += "," + "['" + xt + "'," + xv + "]"; 
			}
		}
		
		request.setAttribute("data", data);
		
		return "success";
	}

	public String liverAnaly_averageAnaly() {
		
		HttpServletRequest request = ServletActionContext.getRequest();
		
		List<Object[]> resList = liverAnalyService.liverAnaly_averageAnaly();
		String data = "";
		for(int i=0; i<resList.size(); i++) {
			Object[] objArr = resList.get(i);
			String xt = (String)objArr[0];
			String xv = ((BigDecimal)objArr[1]).toString();
			
			if(i == 0) {
				data = "[" + xt + "," + xv + "]"; 
			} else {
				data += "," + "[" + xt + "," + xv + "]"; 
			}
		}
		
		request.setAttribute("data", data);
		
		return "success";
	}

	public String liverAnaly_sexualAnaly() {
		
		HttpServletRequest request = ServletActionContext.getRequest();
		
		List<Object[]> resList = liverAnalyService.liverAnaly_sexualAnaly();
		String data = "";
		for(int i=0; i<resList.size(); i++) {
			Object[] objArr = resList.get(i);
			String xt = (String)objArr[0];
			String xv = ((BigInteger)objArr[1]).toString();
			
			if(i == 0) {
				data = "['" + xt + "'," + xv + "]"; 
			} else {
				data += "," + "['" + xt + "'," + xv + "]"; 
			}
		}
		
		request.setAttribute("data", data);
		
		return "success";
	}
}
